package libcore.net.core;

import libcore.util.DataParseUtil;
import okhttp3.OkHttpClient;
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by jaaksi on 2017/4/29.
 */
public abstract class BaseRetrofitCreator {

  public Retrofit create() {
    return createBuilder().build();
  }

  public Retrofit.Builder createBuilder() {
    return new Retrofit.Builder()
      .baseUrl(getBaseUri())
      .client(getHttpClient())
      //.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .addConverterFactory(getConverterFactory());
  }

  public Converter.Factory getConverterFactory() {
    return GsonConverterFactory.create(DataParseUtil.mGson);
  }

  public abstract OkHttpClient getHttpClient();

  public abstract String getBaseUri();
}
